<template>
  <view class="good_item">
    <view class="checkbox l">
      <wd-checkbox v-model="item.checkbox" shape="square" checked-color="#ffcc00" @change="oncheckbox"></wd-checkbox>
    </view>
    <view class="good_info l">
      <view class="good_name">{{ item.skuName }}</view>
      <view class="good_specs">{{ item.remark || '无备注' }}</view>
    </view>
    <view class="good_cp r">
      <wd-input-number v-model="item.goodsCount" :min="1" :max="item.goodsCount" @change="change" />
    </view>
  </view>
</template>

<script lang="ts" setup>
import { err } from '@/utils/uniapi';
interface Item {
  goodsCount: string;
  checkbox: boolean;
  skuName: string;
  remark: string;
  returncount: any;
}
const props = defineProps<{
  item: Item;
  index: number;
}>();
const emit = defineEmits(['bool', 'count']);
function oncheckbox({ value }) {
  try {
    const bool = value;
    const item = props.item;
    item.checkbox = bool;
    emit('bool', { items: item, index: props.index });
  } catch (error) {
    err(error);
    throw error;
  }
}
function change({ value }) {
  try {
    const count = value;
    const item = props.item;
    item.returncount = count;
    emit('count', { items: item, index: props.index });
  } catch (error) {
    err(error);
    throw error;
  }
}
</script>

<style scoped lang="scss">
.good_item {
  margin-top: 12rpx;
  width: 100%;
  height: 108rpx;
  overflow: hidden;
  .checkbox {
    margin-top: 20rpx;
  }
}
</style>
